@model LndSeedBackupViewModel
@{
    ViewData.SetLayoutModel(new LayoutModel(nameof(ServerNavPages.Services), StringLocalizer["LND Seed Backup"])
        .SetCategory(WellKnownCategories.Server));
}

<div class="sticky-header">
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item">
                <a asp-action="Services" text-translate="true">Services</a>
            </li>
            <li class="breadcrumb-item active" aria-current="page">@ViewData["Title"]</li>
        </ol>
        <h2>@ViewData["Title"]</h2>
    </nav>
</div>
<partial name="_StatusMessage" />

@if (Model.IsWalletUnlockPresent)
{
    <div class="row">
        <div class="col-lg-8">
            <div class="form-group">
                <p text-translate="true">The LND seed backup is useful to recover on-chain funds of your LND wallet in case of a corruption of your server.</p>
                <p>The recovering process is documented by LND on <a href="https://github.com/lightningnetwork/lnd/blob/master/docs/recovery.md" rel="noreferrer noopener">this page</a>.</p>
            </div>
            <button class="btn btn-primary @(Model.Removed ? "collapse" : "")" id="details" type="button">See confidential seed information</button>

            @if (Model.Removed)
            {
                <div class="alert alert-light d-flex align-items-center" role="alert">
                    <vc:icon symbol="warning" />
                    <span class="ms-3" id="Seed">@Model.Seed</span>
                </div>
            }
            else
            {
                <div class="form-group @(Model.Removed ? "" : "collapse")">
                    <div class="form-group">
                        <label asp-for="Seed" class="form-label"></label>
                        <div class="input-group">
                            <input asp-for="Seed" type="password" class="form-control" value="@Model.Seed">
                            <button type="button" class="btn btn-secondary px-3 only-for-js" title="@StringLocalizer["Toggle seed visibility"]" data-toggle-password="#Seed">
                                <vc:icon symbol="actions-show" />
                            </button>
                        </div>
                    </div>
                    <div class="form-group">
                        <label asp-for="WalletPassword" class="form-label" text-translate="true">Password</label>
                        <div class="input-group">
                            <input asp-for="WalletPassword" type="password" class="form-control" value="@Model.WalletPassword">
                            <button type="button" class="btn btn-secondary px-3 only-for-js" title="@StringLocalizer["Toggle password visibility"]" data-toggle-password="#WalletPassword">
                                <vc:icon symbol="actions-show" />
                            </button>
                        </div>
                    </div>
                </div>
                <div class="form-group collapse">
                    <form method="get" asp-action="RemoveLndSeed" asp-route-serviceName="@Context.GetRouteValue("serviceName")" asp-route-cryptoCode="@Context.GetRouteValue("cryptoCode")">
                        <button id="delete" class="btn btn-primary" type="submit" data-bs-toggle="modal" data-bs-target="#ConfirmModal" data-confirm-input="@StringLocalizer["DELETE"]" text-translate="true">Delete LND seed from server</button>
                    </form>
                </div>
            }
        </div>
    </div>
}

@if (!Model.Removed)
{
    <partial name="_Confirm" model="@(new ConfirmModel(StringLocalizer["Delete LND seed"], StringLocalizer["This action will permanently delete your LND seed and password. You will not be able to recover them if you don't have a backup."], StringLocalizer["Delete"]))"/>
}

@section PageFootContent {
    <script>
        delegate('click', '#Seed', event => { event.target.select() })
        delegate('click', '#WalletPassword', event => { event.target.select() })
        delegate('click', '#delete', event => { event.preventDefault() })
        delegate('click', '#details', event => {
            document.querySelectorAll('.form-group.collapse').forEach(el => el.classList.remove('collapse'))
            event.target.classList.add('collapse')
        })
    </script>
}
